package com.moon.back.advice;

import cn.dev33.satoken.util.SaResult;
import com.moon.back.exception.DebounceException;
import com.moon.back.exception.UserBusinessException;
import lombok.extern.slf4j.Slf4j;
import org.redisson.client.RedisException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
 * @author 16905
 */
@Slf4j
@ResponseBody
@RestControllerAdvice
public class GlobalExceptionHandler {
    // 全局异常拦截 
    @ExceptionHandler(value =  UserBusinessException.class)
    public SaResult handlerException(UserBusinessException e) {

        log.info("异常拦截器 获取 {}",e.getMessage());
        return SaResult.data(e);
    }
    @ExceptionHandler(value =  RedisException.class)
    public SaResult handlerException(RedisException e) {

        log.info("异常拦截器 redis 错误信息 获取 {}",e.getMessage());
        String message = "内部中间件错误, 请联系管理员处理";

        return SaResult.error(message);
    }

    @ExceptionHandler(value =  DebounceException.class)
    public SaResult handlerDebounceException(DebounceException e) {

        log.info("异常拦截器获取防抖处理异常: {}",e.getMessage());
        return SaResult.error(e.getMessage());
    }
}
